<template>
  <div class="carshop">
    <!-- 活动分类 -->
    <van-tabs 
    v-model="active" 
    background="#111214"
    color="transparent"
    title-inactive-color="#fff"
    title-active-color="#fff"
    >
      <van-tab 
        v-for="(item,index) in topBars1" 
        :key="index"
        
        >
          <template #title> 
            <div>
              <van-icon :name="item.logo" size="24" @click="jumpCarmarket(index)"/>
            </div>
            {{item.text}}
          </template>
      </van-tab>
    </van-tabs>
    <!-- 标志 -->
    <van-grid 
    :border="false" 
    :column-num="5"
    >
      <van-grid-item
      v-for="item in topBars2"
      :key="item.code"
      @click="jumpBrands">
        <van-icon :name="item.logo" size="36"/>
        {{item.text}}
      </van-grid-item>
    </van-grid>
    <!-- 车型分类 -->
    <div class="carType">
      <van-grid :column-num="5">
        <van-grid-item v-for="item in carType" 
        :key="item.code" 
        :text="item.display_name"
        @click="jumpclassify" />
    </van-grid>
    </div>
    <!-- 广告 -->
    <div class="ad">
      <img src="https://youjia.cdn.bcebos.com/ad_commercial/16633384167700032b2c.jpg@!default_youjia">
      <div class="hint">广告</div>
    </div>
    <!-- 汽车品牌 -->
    <van-index-bar highlight-color="#333" >
      <div v-for="(item,index) in brands" :key="index">
        <van-index-anchor  :index="item.letterName" class="initial"/>
        <div v-for="(value,el) in item.brandList" :key="el" class="trade">
          <img :src="value.logo">
          <van-cell :title="value.name" />
        </div>
      </div>
    </van-index-bar>
  </div>
</template>

<script>
import axios from 'axios'
export default {
  name: 'carshop',
  data() {
    return {
      active:0,
      topBars1:[],
      topBars2:[],
      carType:[],
      brands:[]
    }
  },
  async created(){
    await axios.get('http://localhost:9527/carShopdata.json')
      .then(res=>{
        console.log(res)
        this.topBars1 = res.data.Result.topBars[0],
        this.topBars2 = res.data.Result.topBars[1],
        this.carType = res.data.Result.conditionList
        this.brands =  res.data.Result.brands
      })
  },
  methods:{
    jumpBrands(){
      this.$router.push('/brands')
    },
    jumpclassify(){
      this.$router.push('/classify')
    },
    jumpCarmarket(index){
      if(index === 0){
        this.$router.push('/caronmarket')
      }else if(index === 2){
        this.$router.push('/cardiscount')
      }
     
    }
  }
}
</script>

<style lang="scss" scoped>
.carshop{
   padding-top: 46px;
  .van-tab div{
    text-align: center; 
  }
  .ad{
    height: 80px;
    margin-top: 10px;
    position: relative;
    img{
      height: 100%;
      width: 92%;
      display: block;
      margin: 0 auto;
      border-radius: 4px;
    }
    .hint{
      position: absolute;
      font-size: 12px;
      line-height: 12px;
      right: 24px;
      bottom: 6px;
      padding: 3px;
      color: #fff;
      border: 0.5px solid #fff;
      border-radius: 3px;
      background: rgba(0,0,0,.3);
    }
  }
}
.carshop ::v-deep{
  .van-tabs__wrap{
      height: 100px;
  }
  .van-grid-item{
    font-size: 12px;
    height: 100px;
    color: #242a33;
    .van-icon{
      margin-bottom: 6px;
    }
  }
  .carType{
      .van-hairline--top{
        height: 76px;
        width: 94%;
        margin: 0 auto;
        .van-grid-item{
          height: 30px;
          font-size: 12px;
          line-height: 30px;
        }
    }
    .van-grid-item__content::after {
        z-index: 1;
        border-width: 0; 
    }
    .van-grid-item__content {
      border-radius: 4px;
      background: #f6f6f6;
      color: #4f535e;
      height: 30px;
      margin-left: 5px;
      margin-right: 5px;
    }
    [class*=van-hairline]::after{
      border: 0;
    }
  }
  .van-index-bar{
    .van-index-bar__sidebar{
      position: fixed;
      right: -4px;
      top: center;
      height: 400px;
      display: flex;
      flex-direction: column;
      justify-content: space-around;
      font-size: 12px;
      color: #4f535e;
      font-weight: 100;
    }
    .trade{
      margin: 0 auto;
      display: flex;
      width: 94%;
      height: 60px;
      align-items: center;
      justify-content: flex-start;
      img{
        width: 40px;
        height: 40px;
      }
      .van-cell__title{
        font-size: 16px;
        color: #333;
      }
    }
    .van-index-anchor {
      z-index: -1;
    }
    
  }
  .van-grid-item__content {
      padding: 16px 5px;
    }
}
</style>
